#include <iostream>
#include <queue>

using namespace std;

priority_queue<int, vector<int>, greater<int>> heap;

int main()
{
	int T;
	
	cin >> T;
	
	while (T -- )
	{
		int op, x;
		
		cin >> op;
		
		if (op == 1)
		{
			cin >> x;
			heap.push(x);
		}
		else if (op == 2) cout << heap.top() << endl;
		else heap.pop();
	}
	
	return 0;
}